qx.Class.define("rocketspocket.ui.twitter.MainWindow",
{
	extend : qx.ui.window.Window,
	construct : function()
	{
		this.base(arguments, this.tr("Twitter by pham"), "rocketspocket/icons/twitter-small-icon.png");
		this.__initLayout();
	},
	events :
	{
		"reload" : "qx.event.type.Event",
		"post" : "qx.event.type.Data"
	},
	members :
	{
		__list : null,
		__textarea : null,
		
		__initLayout : function(){
			// hide the window buttons
			//this.setShowClose(false);
			this.setShowMaximize(false);
			this.setShowMinimize(false);
			
			// adjust size
			this.setWidth(260);
			this.setHeight(600);
			
			// add the layout
			var layout = new qx.ui.layout.Grid(0, 0);
			this.setLayout(layout);
			
			// toolbar
			var toolbar = new qx.ui.toolbar.ToolBar();
			this.add(toolbar, {row: 0, column: 0, colSpan: 2});
			
			// reload button
			var reloadButton = new qx.ui.toolbar.Button(this.tr("Reload"));
			reloadButton.addListener("execute", function() {
				this.fireEvent("reload");
			}, this)
			toolbar.add(reloadButton);
			
			// spacer
			toolbar.addSpacer();
			// settings button
			var settingsWindow = null;
			var settingsButton = new qx.ui.toolbar.Button(this.tr("Preferences"));
			toolbar.add(settingsButton);
			settingsButton.setToolTipText(this.tr("Change the applications settings."));
			settingsButton.addListener("execute", function() {
				if (!settingsWindow) {
					settingsWindow = new rocketspocket.ui.twitter.SettingsWindow();
					settingsWindow.moveTo(720,30);
				}
				settingsWindow.open();
			}, this);
			
			// list
			this.__list = new qx.ui.list.List(),
			this.add(this.__list, {row: 1, column: 0, colSpan: 2});
			this.setContentPadding(0);
			layout.setRowFlex(1, 1);
			layout.setColumnFlex(0, 1);
			
			// textarea
			this.__textarea = new qx.ui.form.TextArea();
			this.__textarea.addListener("input", function(e) {
				var value = e.getData();
				postButton.setEnabled(value.length < 140 && value.length > 0);
			}, this);
			this.__textarea.setPlaceholder(this.tr("Enter your message here..."));
			this.add(this.__textarea, {row: 2, column: 0});
			
			// post button
			var postButton = new qx.ui.form.Button(this.tr("Post"));
			postButton.addListener("execute", function() {
				this.fireDataEvent("post", this.__textarea.getValue());
			}, this);
			postButton.setEnabled(false);
			postButton.setMinWidth(60);
			postButton.setToolTipText(this.tr("Post this message on twitter."));
			this.add(postButton, {row: 2, column: 1});
		},
		
		getList : function() {
			return this.__list;
		},
		
		clearPostMessage : function() {
			this.__textarea.setValue(null);
		}
	}
});